<?php

namespace Admin\Model;

/**
 * 
 * 文件用途描述: 安装统计
 * @authors xiaohui
 * @date    2017-09-28 14:11:16
 */
class InstallcountModel extends BaseModel {
    
    /**
	 * 安装统计
	 */
	public function installcount($params){

		if(!empty($params['map'])){
			$sta_day = $params['map']['stadate'];
			$end_day = $params['map']['enddate'];

			$sta_time = strtotime($sta_day);
			$end_time = strtotime($end_day)+3600*24-1;
		}else{
			$sta_day = date("Y-m-d",mktime(0,0,0,date("m"),date("d")-date("w")+1,date("Y")));
			$end_day = date("Y-m-d",mktime(23,59,59,date("m"),date("d")-date("w")+7,date("Y")));

			$sta_time = mktime(0,0,0,date("m"),date("d")-date("w")+1,date("Y"));
			$end_time = mktime(23,59,59,date("m"),date("d")-date("w")+7,date("Y"));
		}
		$date_arr = printDate($sta_day,$end_day);
		$date = '';
		foreach($date_arr as $key => $val){
			$date[] = $val['day'];

			$andmap['time'] = array('between',array($val['time'],$val['time']+3600*24-1));
			$andmap['plat'] = array('EQ',2);//安卓平台
			$And[] = intval($this -> where($andmap) -> count());

			$iosmap['time'] = array('between',array($val['time'],$val['time']+3600*24-1));
			$iosmap['plat'] = array('EQ',1);//IOS平台
			$Ios[] = intval($this -> where($iosmap) -> count());
		}

		$map['time'] = array('between',array($sta_time,$end_time));
		$count = $this -> where($map) -> count();

		$data['date'] = $date;
		$data['list'] = array(
			'AND' => $And,
			'IOS' => $Ios
		);
		$data['count'] = $count;
		return $data;
	}
}